/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 * Version：V1.0.2(20230701).
 */
package top.hiai._admin.words;


import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;

import top.hiai.common.model.Words;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top
* @Introduction 类的介绍
*/

public class WordsAdminService {


	public static final WordsAdminService me = new WordsAdminService();
	
	private Words wordsDao = new Words().dao();

	/**
	 * 后台管理所有文章分页
	 */
	public Page<Words> paginate(int pageNum,int pageSize) {
		Page<Words> wordsPage = wordsDao.paginate(pageNum, pageSize, "select *", "from bbs_sensitive_words order by id desc");
		return wordsPage;
	}
	
	/**
	 * 根据ID查找
	 * @return
	 */
	public Words findById(int id) {
		return wordsDao.findById(id);
	}
	/**
	 * 添加敏感词
	 * @param word
	 * @param status
	 * @param word_pinyin
	 * @return
	 */
	public Boolean wordsAdd(String word,int status,String word_pinyin){
		Words words = new Words();
		words.setWord(word);
		words.setStatus(status);
		words.setWord_pinyin(word_pinyin);
		if(words.save()){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 修改敏感词
	 * @param word
	 * @param status
	 * @param word_pinyin
	 * @return
	 */
	public Boolean wordsEdit(int id,String word,int status,String word_pinyin){
		Words words = new Words();
		words.setId(id);
		words.setWord(word);
		words.setStatus(status);
		words.setWord_pinyin(word_pinyin);
		if(words.update()){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 删除敏感词
	 * @param id
	 */
	public void wordsDelete(int id){
		wordsDao.deleteById(id);
	}
	
	/**
	 * 锁定敏感词
	 * @return
	 */
	public Ret lock(int id) {
		int n = Db.update(" update bbs_sensitive_words set status=? where id=?", Words.WORDS_OK, id);
		if (n > 0) {
			return Ret.ok("msg", "启用成功");
		} else {
			return Ret.fail().set("msg", "启用失败");
		}
	}

	/**
	 * 解锁敏感词
	 * @return
	 */
	public Ret unlock(int id) {
		int n = Db.update("update bbs_sensitive_words set status = ? where id = ?", Words.WORDS_NOT , id);
		if (n > 0) {
			return Ret.ok("msg", "解锁成功");
		} else {
			return Ret.fail().set("msg", "解锁失败，可能是账户未激活，请查看账户详情");
		}
	}
}